Conditions | 17 |
Paths | 17 |
Total Lines | 21 |
Code Lines | 19 |
Lines | 1 |
Ratio | 4.76 % |
Changes | 0 |
Complex classes like exports.toOpcode often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | /* |
||
28 | View Code Duplication | exports.toOpcode = function (code) { |
|
29 | switch (code.toUpperCase()) { |
||
30 | case 'QUERY': return 0 |
||
31 | case 'IQUERY': return 1 |
||
32 | case 'STATUS': return 2 |
||
33 | case 'OPCODE_3': return 3 |
||
34 | case 'NOTIFY': return 4 |
||
35 | case 'UPDATE': return 5 |
||
36 | case 'OPCODE_6': return 6 |
||
37 | case 'OPCODE_7': return 7 |
||
38 | case 'OPCODE_8': return 8 |
||
39 | case 'OPCODE_9': return 9 |
||
40 | case 'OPCODE_10': return 10 |
||
41 | case 'OPCODE_11': return 11 |
||
42 | case 'OPCODE_12': return 12 |
||
43 | case 'OPCODE_13': return 13 |
||
44 | case 'OPCODE_14': return 14 |
||
45 | case 'OPCODE_15': return 15 |
||
46 | } |
||
47 | return 0 |
||
48 | } |
||
49 |